<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <input type="text" id="username" name="username">
        <input type="password" id="password" name="password">
        <p>
            <input type="submib" value="提交">
        </p>
    </form>
</body>
</html>
<script>
    let username = document.querySelector('#username');
    let password = document.querySelector('#password');
    // console.log(username);
    // username.onblur=function(){}
    username.addEventListener('blur',()=>{
        if(username.value===''){
            username.setAttribute('placeholder','请输入名字')
        }
    })
    username.addEventListener('focus',()=>{
            username.removeAttribute('placeholder')
    })
    password.addEventListener('blur',()=>{
        if(password.value===''){
            alert('密码不能为空')
        }
    })

</script>